//
//  FZReportView.swift
//  MyWeiBo
//
//  Created by fangzhengwei on 2017/3/31.
//  Copyright © 2017年 fangzhengwei. All rights reserved.
//

import UIKit
import SnapKit
class FZReportView: UIView {
    
    var statusReportModel : FZStatusViewModel?{
        
        didSet {
            
            reportLab.attributedText = statusReportModel?.retweetAttributeString
            pictureView.statusPictureModel = statusReportModel?.statusModel?.pic_urls
            
            if let reportPicData = statusReportModel?.statusModel {
                
                judgeContrain(statusModel: reportPicData)
            }
        }
    }
    
    var reportConstraint: Constraint?
    //配图
    fileprivate lazy var pictureView : FZPictureView = FZPictureView()
    
    fileprivate lazy var reportLab : UILabel = {
        
        let webText = UILabel()
        webText.font = UIFont.systemFont(ofSize: 14)
        webText.textColor = UIColor.darkGray
        webText.text = "我热爱学习,学习使我快乐我热爱学习,学习使我快乐我热爱学习,学习使我快乐我热爱学习,学习使我快乐我热爱学习,学习使我快乐我热爱学习,学习使我快乐我热爱学习,学习使我快乐"
        webText.numberOfLines = 0
        return webText
    }()
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.init(patternImage: UIImage(named:"timeline_retweet_background")!)
        addSubview(reportLab)
        addSubview(pictureView)
        reportLab.snp.makeConstraints({ (make) in
            
            make.top.equalTo(self)
            make.leading.equalTo(self).offset(10)
            make.right.equalTo(self).offset(-10)
            
        })
        
        pictureView.snp.makeConstraints { (make) in
           make.top.equalTo(reportLab.snp.bottom).offset(10)
           make.left.equalTo(reportLab.snp.left)
           make.size.equalTo(CGSize(width: 100, height: 100))
        }
        
        self.snp.makeConstraints({ (make) in
           reportConstraint = make.bottom.equalTo(pictureView.snp.bottom).constraint
            
        })

    }
    func judgeContrain(statusModel : FZStatusModel) {
        
        reportConstraint?.deactivate()
        
        if statusModel.pic_urls?.count == 0 {
            
            self.snp.makeConstraints({ (make) in
                reportConstraint = make.bottom.equalTo(reportLab.snp.bottom).offset(10).constraint
            })
            pictureView.isHidden = true
            
        }else{
            
            self.snp.makeConstraints({ (make) in
                
                reportConstraint = make.bottom.equalTo(pictureView.snp.bottom).offset(10).constraint
                
            })
            pictureView.isHidden = false
        }
        
    }

    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
